import React, { useState, useEffect } from 'react'
// 引入 ECharts 主模块

import * as echarts from 'echarts';
import Styles from './index.css'


const defaultOption = {
    title: {
        text: '某站点用户访问来源',
        subtext: '纯属虚构',
        left: 'center'
    },
    tooltip: {
        trigger: 'item'
    },
    legend: {
        orient: 'vertical',
        left: 'left',
    },
    series: [
        {
            name: '访问来源',
            type: 'pie',
            radius: '50%',
            data: [
                { value: 1048, name: '搜索引擎' },
                { value: 735, name: '直接访问' },
                { value: 580, name: '邮件营销' },
                { value: 484, name: '联盟广告' },
                { value: 300, name: '视频广告' }
            ],
            emphasis: {
                itemStyle: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }
    ]
};
const Index = () => {
    const [chart, setChart] = useState('')
    console.log("echarts", echarts)
    const resize = () => {
        chart && chart.resize();
    }
    useEffect(() => {
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('chart_AgeAistributiont'));
        setChart(myChart)
        // 绘制图表
        myChart.setOption(defaultOption);
        window.addEventListener('resize', resize);
    }, [])
    return <>
        <div className='pane-title'>
            饼图-年龄分布
        </div>
        <div className={Styles.chart} id='chart_AgeAistributiont' style={{ height: '100%', width: '100%' }} ></div>
    </>
}

export default Index